package com.demo0308.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;


public class Demo01Filter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("拦截器 Demo01 被创建");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpSession session = request.getSession();

        System.out.println("拦截器 Demo01 被访问前");
        filterChain.doFilter(request, servletResponse);
        System.out.println("拦截器 Demo01 被访问后");

    }

    @Override
    public void destroy() {
        System.out.println("拦截器 Demo01 被销毁");
    }
}
